package com.anolesoft.yr.mbus.code.service.impl;

import com.anolesoft.yr.mbus.code.dto.CodeMainDTO;
import com.anolesoft.yr.mbus.code.dto.CodeMaxSequenceQueryDTO;
import com.anolesoft.yr.mbus.code.entity.CodeMainDO;
import com.anolesoft.yr.mbus.code.entity.CodeMaxSequenceQueryDO;
import com.anolesoft.yr.mbus.code.mapper.CodeMaxSequenceQueryMapper;
import com.anolesoft.yr.mbus.code.service.CodeMaxSequenceService;
import com.anolesoft.yr.util.CustomBeanUtils;
import com.anolesoft.yr.util.PageData;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author zhj
 * @date 2020/9/27 19:45
 */
@Service
public class CodeMaxSequenceServiceImpl implements CodeMaxSequenceService {
    @Autowired
    private CodeMaxSequenceQueryMapper codeMaxSequenceQueryMapper;

    @Override
    public PageData<List<CodeMaxSequenceQueryDTO>> selectList(CodeMaxSequenceQueryDTO codeMaxSequenceQueryDTO, Integer limit, Integer curr) {
        CodeMaxSequenceQueryDO codeMaxSequenceQueryDO = CodeMaxSequenceQueryDO.builder().codeMainCodeName(codeMaxSequenceQueryDTO.getCodeMainCodeName()).build();
        Page<CodeMaxSequenceQueryDO> page = new Page<>(curr, limit);
        List<CodeMaxSequenceQueryDTO> codeItemDTOS = codeMaxSequenceQueryMapper.selectPageList(codeMaxSequenceQueryDO, page).stream().map(t -> CodeMaxSequenceQueryDTO.builder()
                .codeItemUid(t.getCodeItemUid())
                .codeMainCodeDesc(t.getCodeMainCodeDesc())
                .codeMainCodeName(t.getCodeMainCodeName())
                .codeMainGeneClass(t.getCodeMainGeneClass())
                .codeMainUid(t.getCodeMainUid())
                .maxSequence(t.getMaxSequence())
                .objuid(t.getObjuid())
                .propertyValue(t.getPropertyValue())
                .sequenceName(t.getSequenceName())
                .build()).collect(Collectors.toList());
        return new PageData<>((int) page.getTotal(), codeItemDTOS);
    }
}
